package com.infore.statisticsAndAlarm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.infore.statisticsAndAlarm.constant.Constants;
import com.infore.statisticsAndAlarm.entity.KnowledgeKeyWorld;
import com.infore.statisticsAndAlarm.enums.ResultStatus;
import com.infore.statisticsAndAlarm.repository.IKeyWorldRepository;
import com.infore.statisticsAndAlarm.service.IKeyWorldService;
import com.infore.statisticsAndAlarm.util.ResultEntity;

@Service
public class KeyWorldServiceImpl implements IKeyWorldService {

	@Autowired
	private IKeyWorldRepository iKeyWorldRepository;

	public ResultEntity query() {
		List<KnowledgeKeyWorld> list = iKeyWorldRepository.findByOrderByKeyWorldNumDesc();
		//如果关键词数量超过500条则删除剩余的关键词
		if (list.size() > 500) {
			List<KnowledgeKeyWorld> outList = new ArrayList<KnowledgeKeyWorld>();
			outList.addAll(500, list);
			iKeyWorldRepository.deleteInBatch(outList);
		}
		//截取前7条数据返回
		if (list.size() > 7) {
			list = list.subList(0, 6);
		}
		return new ResultEntity(ResultStatus.SUCCESS, Constants.QUERY_SUCCESS).setDataList(list);
	}

}
